<?php
/**
 * @Desc 
 * @Auth Menory
 * @Date 2016年3月7日 14:03:41
 */
namespace Act;
use Lib\Action;

class Check extends Action {
    public function __construct($server, $RSMethod) {
        parent::__construct($server, $RSMethod);
        $exclude = ['/login', '/logout'];

        // debug start
        $menus = [
            ['menu_id' => 1, 'menu_name' => '首页', 'menu_url' => '/index', 'online' => 1, 'is_show' => 1],
            ['menu_id' => 2, 'menu_name' => '个人信息', 'menu_url' => '/os/profile', 'online' => 1, 'is_show' => 1],
        ];
        session('uid', 1);
        session('user_info', ['user_id' => 1, 'user_name' => 'admin', 'status' => 1, 'menus' => $menus]);
        // debug end

        if (isset($exclude[$this->act_name]))
            return ;

        $admUserModel = model('#User');
        // 是否登录
        if (!$admUserModel->isLogin())
            return redirect('/login');

        $uid = session('uid');
        // 是否有注册该链接
        $menu = model('#MenuUrl')->getUserMenuByUrl($this->act_name);
        if ($uid != 1 && empty($menu))
            return http_status('403 Permission denied', 'The menu did not join the permissions list', 403);

        // 是否有权限访问
        if ($uid != 1 && !$admUserModel->checkActionAccess())
            return http_status('403 Permission denied', 'The menu did not join the permissions list', 403);

    }
}